using UnityEngine;
using UnityEngine.UI;

public class ArenaLevel : Arena
{
	public Image centerBg;

	public Image centerLockedLock;

	public Image centerLockedPoint;

	public Text centerLockedLabel;

	public Image centerUnlockedPoint;

	public Text centerUnlockedLabel;

	public Button buttonArena;

	public int currentPoints;

	public override void Init()
	{
		base.Init();
		centerBg.name = "arena_" + arenaNumber + "_" + centerBg.name;
		centerLockedLock.name = "arena_" + arenaNumber + "_" + centerLockedLock.name;
		centerLockedPoint.name = "arena_" + arenaNumber + "_" + centerLockedPoint.name;
		centerLockedLabel.name = "arena_" + arenaNumber + "_" + centerLockedLabel.name;
		centerUnlockedPoint.name = "arena_" + arenaNumber + "_" + centerUnlockedPoint.name;
		centerUnlockedLabel.name = "arena_" + arenaNumber + "_" + centerUnlockedLabel.name;
		buttonArena.name = buttonArena.name + " " + arenaNumber;
		int unlockPointsForArena = EconomySettings.GetUnlockPointsForArena(arenaNumber);
		centerLockedLabel.text = unlockPointsForArena.ToString();
		if (unlockPointsForArena < 10)
		{
			centerLockedLabel.rectTransform.anchoredPosition = new Vector2(15f, centerLockedLabel.rectTransform.anchoredPosition.y);
			centerLockedPoint.rectTransform.anchoredPosition = new Vector2(59f, centerLockedPoint.rectTransform.anchoredPosition.y);
		}
		else if (unlockPointsForArena < 100)
		{
			centerLockedLabel.rectTransform.anchoredPosition = new Vector2(-7f, centerLockedLabel.rectTransform.anchoredPosition.y);
			centerLockedPoint.rectTransform.anchoredPosition = new Vector2(37f, centerLockedPoint.rectTransform.anchoredPosition.y);
		}
		else
		{
			centerLockedLabel.rectTransform.anchoredPosition = new Vector2(-26f, centerLockedLabel.rectTransform.anchoredPosition.y);
			centerLockedPoint.rectTransform.anchoredPosition = new Vector2(18f, centerLockedPoint.rectTransform.anchoredPosition.y);
		}
	}

	public override void SetParenting()
	{
		base.SetParenting();
		centerBg.rectTransform.SetParent(scrollLevels.GetLayer(0));
		centerLockedLock.rectTransform.SetParent(scrollLevels.GetLayer(1));
		centerLockedPoint.rectTransform.SetParent(scrollLevels.GetLayer(1));
		centerLockedLabel.rectTransform.SetParent(scrollLevels.GetLayer(2));
		centerLockedLabel.rectTransform.SetAsLastSibling();
		centerUnlockedPoint.rectTransform.SetParent(scrollLevels.GetLayer(1));
		centerUnlockedLabel.rectTransform.SetParent(scrollLevels.GetLayer(2));
		centerUnlockedLabel.rectTransform.SetAsLastSibling();
		buttonArena.GetComponent<RectTransform>().SetParent(scrollLevels.GetLayer(3));
	}

	public override void UpdateVisibility()
	{
		base.UpdateVisibility();
		centerBg.enabled = isVisible;
		centerLockedLock.enabled = isVisible;
		centerLockedPoint.enabled = isVisible;
		centerLockedLabel.enabled = isVisible;
		centerUnlockedPoint.enabled = isVisible;
		centerUnlockedLabel.enabled = isVisible;
	}

	public override void UpdateAspect()
	{
		if (!Economy.hasInstance)
		{
			return;
		}
		base.UpdateAspect();
		currentPoints = 0;
		for (int i = 0; i < levelsButton.Length; i++)
		{
			if (levelsButton[i] != null)
			{
				currentPoints += Economy.GetLevelData(levelsButton[i].levelNumber).currentPoints;
			}
		}
		centerUnlockedLabel.text = currentPoints.ToString();
		if (IsLocked())
		{
			buttonArena.gameObject.SetActive(true);
			centerBg.sprite = SpriteManager.GetInstance().spriteArenaLocked;
			centerLockedLock.gameObject.SetActive(true);
			centerLockedPoint.gameObject.SetActive(true);
			centerLockedLabel.gameObject.SetActive(true);
			centerUnlockedPoint.gameObject.SetActive(false);
			centerUnlockedLabel.gameObject.SetActive(false);
		}
		else
		{
			buttonArena.gameObject.SetActive(false);
			centerBg.sprite = SpriteManager.GetInstance().spriteArenaUnlocked;
			centerLockedLock.gameObject.SetActive(false);
			centerLockedPoint.gameObject.SetActive(false);
			centerLockedLabel.gameObject.SetActive(false);
			centerUnlockedPoint.gameObject.SetActive(true);
			centerUnlockedLabel.gameObject.SetActive(true);
		}
	}

	public void OnButtonArena()
	{
		if (IsLocked())
		{
			UserInterface.GetInstance().OnLevelTap(levelsButton[0].levelNumber, GameMode.Normal);
		}
	}
}
